using System;
using System.Data;
using System.Collections;
using System.Runtime.Serialization;
using Widgetsphere.Core.Util;
using Widgetsphere.Core.DataAccess;
using System.Collections.Generic;
using Acme.Sales.Business.Objects;
using Acme.Sales.Domain.Objects;
using System.Xml;

namespace Acme.Sales.Business.SelectCommands
{
	#region CustomerSelectAll

	/// <summary>
	/// The select command used to select all rows from the 'Customer' table
	/// </summary>
	[Serializable]
	public partial class CustomerSelectAll : SelectCommandBase, ISerializable
	{

		#region Serialization

		/// <summary>
		/// Serialization constructor
		/// </summary>
		protected CustomerSelectAll(SerializationInfo info, StreamingContext context): base(info,context)
		{
		}

		/// <summary>
		/// Method used internally for serialization
		/// </summary>
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			base.GetObjectData(info, context);
		}

		#endregion 

		/// <summary>
		/// Default constructor
		/// </summary>
		public CustomerSelectAll()
		{
		}

		/// <summary>
		/// Creates a persistable domainCollection
		/// </summary>
		public override IDomainCollection CreateDomainCollection()
		{
			DomainCustomerCollection colDomain = new DomainCustomerCollection();
			return colDomain;
		}

		/// <summary>
		/// The stored procedure name to select values to populate a 'Customer' collection
		/// </summary>
		public override string StoredProcedureName
		{
			get { return "[dbo].[gen_CustomerSelect]"; }
		}

		/// <summary>
		/// Initializes the parameters for this select command
		/// </summary>
		protected override void SetupParameterValues(SubDomainBase subDomain)
		{
		}

	}

	#endregion

	#region CustomerSelectByPks

	/// <summary>
	/// A select command that selects objects by primary key
	/// </summary>
	[Serializable]
	public partial class CustomerSelectByPks : SelectCommandBase, ISerializable
	{
		private List<CustomerPrimaryKey> mPrimaryKeys = null;

		#region Serialization

		/// <summary>
		/// Serialization constructor
		/// </summary>
		protected CustomerSelectByPks(SerializationInfo info, StreamingContext context): base(info,context)
		{
			mPrimaryKeys = new List<CustomerPrimaryKey>();
			mPrimaryKeys.AddRange((CustomerPrimaryKey[])info.GetValue("mPrimaryKeys", typeof(CustomerPrimaryKey[])));
		}

		/// <summary>
		/// Method used internally for serialization
		/// </summary>
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			base.GetObjectData(info, context);
			info.AddValue("mPrimaryKeys", mPrimaryKeys.ToArray());
		}

		#endregion 

		/// <summary>
		/// Select objects by primary key
		/// </summary>
		public CustomerSelectByPks(int userid)
		{
			mPrimaryKeys = new List<CustomerPrimaryKey>();
			mPrimaryKeys.Add(new CustomerPrimaryKey(userid));

		}

		/// <summary>
		/// Select objects by a primary key
		/// </summary>
		public CustomerSelectByPks(CustomerPrimaryKey primaryKey)
		{
			mPrimaryKeys = new List<CustomerPrimaryKey>();
			mPrimaryKeys.Add(primaryKey);
		}

		/// <summary>
		/// Select objects by a list of primary keys
		/// </summary>
		public CustomerSelectByPks(IEnumerable<CustomerPrimaryKey> primaryKeys)
		{
			mPrimaryKeys = new List<CustomerPrimaryKey>();
			mPrimaryKeys.AddRange(primaryKeys);
		}

		/// <summary>
		/// Creates a persistable domainCollection
		/// </summary>
		public override IDomainCollection CreateDomainCollection()
		{
			DomainCustomerCollection colDomain = new DomainCustomerCollection();
			return colDomain;
		}

		/// <summary>
		/// The stored procedure name to select values by primary key to populate a 'Customer' collection
		/// </summary>
		public override string StoredProcedureName
		{
			get
			{
				if (mPrimaryKeys.Count == 1) return "[dbo].[gen_CustomerSelectByCustomerSinglePk]";
				else return "[dbo].[gen_CustomerSelectByCustomerPks]";
			}
		}

		/// <summary>
		/// Initializes the parameters for this select command
		/// </summary>
		protected override void SetupParameterValues(SubDomainBase subDomain)
		{
			if (mPrimaryKeys.Count == 1)
			{
				CustomerPrimaryKey key = ((CustomerPrimaryKey)mPrimaryKeys[0]);
				ParameterValues.Add("@user_id", key.UserId);
			}
			else
				ParameterValues.Add("@xml", DomainCustomerCollection.GetPrimaryKeyXml(mPrimaryKeys));
		}

	}

	#endregion

	#region CustomerSelectByCreatedDateRange

	/// <summary>
	/// Select objects by their created date.
	/// </summary>
	[Serializable]
	public partial class CustomerSelectByCreatedDateRange : SelectCommandBase, ISerializable
	{
		private DateTime? mStartDate;
		private DateTime? mEndDate;

		#region Serialization

		/// <summary>
		/// Select objects by their created date.
		/// </summary>
		protected CustomerSelectByCreatedDateRange(SerializationInfo info, StreamingContext context): base(info,context)
		{
			mStartDate = info.GetDateTime("mStartDate");
			mEndDate = info.GetDateTime("mEndDate");
		}

		/// <summary>
		/// Method used internally for serialization
		/// </summary>
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			base.GetObjectData(info, context);
			info.AddValue("mStartDate", mStartDate);
			info.AddValue("mEndDate", mEndDate);
		}

		#endregion 

		/// <summary>
		/// Select objects by their created date.
		/// </summary>
		public CustomerSelectByCreatedDateRange(DateTime? startDate, DateTime? endDate)
		{
			mStartDate = startDate;
			mEndDate = endDate;
		}

		/// <summary>
		/// Creates a persistable domainCollection
		/// </summary>
		public override IDomainCollection CreateDomainCollection()
		{
			DomainCustomerCollection colDomain = new DomainCustomerCollection();
			return colDomain;
		}

		/// <summary>
		/// The stored procedure name to select values to populate a 'Customer' collection in a paged fashion
		/// </summary>
		public override string StoredProcedureName
		{
			get { return "[dbo].[gen_CustomerSelectByCreatedDateRange]"; }
		}

		/// <summary>
		/// Initializes the parameters for this select command
		/// </summary>
		protected override void SetupParameterValues(SubDomainBase subDomain)
		{
			ParameterValues.Add("@start_date", mStartDate);
			ParameterValues.Add("@end_date", mEndDate);
		}

		/// <summary>
		/// Execute this select command on the database
		/// </summary>
		public override IDomainCollection Execute(SubDomainBase subDomain)
		{
			this.SetupParameterValues(subDomain);
			PersistableDomainCollectionBase returnTable = (PersistableDomainCollectionBase)this.CreateDomainCollection();

			IDbCommand fillCommand = PersistableDomainCollectionBase.GetFillCommand(this.ConnectionString, this.StoredProcedureName);
			fillCommand.CommandTimeout = this.DefaultTimeOut;
			PersistableDomainCollectionBase.SetParameterValue(fillCommand, "@start_date", mStartDate);
			PersistableDomainCollectionBase.SetParameterValue(fillCommand, "@end_date", mEndDate);
			returnTable.FillDataTable(this.ConnectionString, fillCommand);
			return returnTable;
		}

	}

	#endregion

	#region CustomerSelectByModifiedDateRange

	/// <summary>
	/// Select objects by their modified date.
	/// </summary>
	[Serializable]
	public partial class CustomerSelectByModifiedDateRange : SelectCommandBase, ISerializable
	{
		private DateTime? mStartDate;
		private DateTime? mEndDate;

		#region Serialization

		/// <summary>
		/// Select objects by their modified date.
		/// </summary>
		protected CustomerSelectByModifiedDateRange(SerializationInfo info, StreamingContext context): base(info,context)
		{
			mStartDate = info.GetDateTime("mStartDate");
			mEndDate = info.GetDateTime("mEndDate");
		}

		/// <summary>
		/// Method used internally for serialization
		/// </summary>
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			base.GetObjectData(info, context);
			info.AddValue("mStartDate", mStartDate);
			info.AddValue("mEndDate", mEndDate);
		}

		#endregion 

		/// <summary>
		/// Select objects by their modified date.
		/// </summary>
		public CustomerSelectByModifiedDateRange(DateTime? startDate, DateTime? endDate)
		{
			mStartDate = startDate;
			mEndDate = endDate;
		}

		/// <summary>
		/// Creates a persistable domainCollection
		/// </summary>
		public override IDomainCollection CreateDomainCollection()
		{
			DomainCustomerCollection colDomain = new DomainCustomerCollection();
			return colDomain;
		}

		/// <summary>
		/// The stored procedure name to select values to populate a 'Customer' collection in a paged fashion
		/// </summary>
		public override string StoredProcedureName
		{
			get { return "[dbo].[gen_CustomerSelectByModifiedDateRange]"; }
		}

		/// <summary>
		/// Initializes the parameters for this select command
		/// </summary>
		protected override void SetupParameterValues(SubDomainBase subDomain)
		{
			ParameterValues.Add("@start_date", mStartDate);
			ParameterValues.Add("@end_date", mEndDate);
		}

		/// <summary>
		/// Execute this select command on the database
		/// </summary>
		public override IDomainCollection Execute(SubDomainBase subDomain)
		{
			this.SetupParameterValues(subDomain);
			PersistableDomainCollectionBase returnTable = (PersistableDomainCollectionBase)this.CreateDomainCollection();

			IDbCommand fillCommand = PersistableDomainCollectionBase.GetFillCommand(this.ConnectionString, this.StoredProcedureName);
			fillCommand.CommandTimeout = this.DefaultTimeOut;
			PersistableDomainCollectionBase.SetParameterValue(fillCommand, "@start_date", mStartDate);
			PersistableDomainCollectionBase.SetParameterValue(fillCommand, "@end_date", mEndDate);
			returnTable.FillDataTable(this.ConnectionString, fillCommand);
			return returnTable;
		}

	}

	#endregion

}
